#pragma once

#define Die(data)   \
	do              \
	{               \
		exit(data); \
	} while (0);

#define CONV(v) (struct sockaddr *)(v)


enum 
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR
};

const int gbacklog = 8;
const int gdefaultsockfd = -1;

bool ParseOneLine(std::string &resquest_in,std::string *out,std::string Sep)
{
	auto pos = resquest_in.find(Sep);
	if(pos == std::string::npos) return false;
	*out = resquest_in.substr(0,pos);
	resquest_in = resquest_in.erase(0,pos+Sep.size());
	return true;
}

bool ParseString(std::string head,std::string HeaderLineSep,std::string *key,std::string *value)
{
	auto pos = head.find(HeaderLineSep);
	if(pos == std::string::npos)
	{
		return false;
	}
	*key = head.substr(0,pos);
	*value = head.substr(pos+HeaderLineSep.size());
	return true;
}